
layui.use(['form', 'layer'], function(){

    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    var integral_rule_url = $('.integral_rule_url').val();
    var save_integral_rule_url = $('.save_integral_rule_url').val();


    // 自定义验证规则
    form.verify({
        open_member: function(value){
            if(value == ''){
                return '开通会员积分不能为空';
            }
            if(!/^\+?[1-9][0-9]*$/.test(value)){
                return '开通会员积分格式不正确，应为大于0的正整数';
            }
        },
        perfect_info: function(value){
            if(value == ''){
                return '完善资料积分不能为空';
            }
            if(!/^\+?[1-9][0-9]*$/.test(value)){
                return '完善资料积分格式不正确，应为大于0的正整数';
            }
        },
        comment: function(value){
            if(value == ''){
                return '评价晒单积分不能为空';
            }
            if(!/^\+?[1-9][0-9]*$/.test(value)){
                return '评价晒单积分格式不正确，应为大于0的正整数';
            }
        },
    });

    // 保存积分规则
    form.on("submit(laySave)", function(data){
        // 弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});

        $.ajax({
            url: save_integral_rule_url,
            data: data.field,
            type: "post",
            dataType: "json",
            success: function(res){
                top.layer.close(index);
                top.layer.msg(res.msg);
                if(res.code == 1){
                    layer.closeAll("iframe");
                }
            },
            error:function(data){
                layer.msg("服务器无响应");
            }
        });
    })

});